As a conventional still image compression scheme, a JPEG scheme using discrete cosine transformation and a scheme using Wavelet transformation are often adopted. An encoding scheme of these types is a variable-length encoding scheme, and hence the code amount changes for each image to be encoded.
According to the JPEG scheme as an international standardization scheme, only one quantization matrix can be defined for an image, and the code amount cannot be adjusted without a prescan. When the JPEG scheme is used in a system which stores data in a limited memory, an overflow of memory may occur.
In order to prevent this, conventional schemes use, for example, a method of re-reading a document upon changing the compression ratio when the actual code amount exceeds an expected code amount, or a method of estimating a code amount in advance by prescan and re-setting quantization parameters to adjust the code amount.
As a conventional code amount control method which executes prescan, for example, there is known a method of storing pre-compressed data in an internal buffer memory, decompressing the data, changing the compression parameter, actually compressing the data, and outputting the compressed data to an external storage. At this time, actual compression requires a higher compression ratio than that of pre-compression.
For example, there is known a method of obtaining a permissible code amount for each pixel block and Huffman-encoding a coefficient prepared by n-time level shifting of the DCT coefficient in order to reduce the code amount. The shift count n is determined from the permissible code amount.
There is also proposed a method of generating encoded data which effectively falls within the size by one image input (Japanese Patent Laid-Open No. 2003-8903). According to this method, two memories for storing encoded data are prepared, and encoded data are stored in the two memories. When the amount of stored encoded data reaches a target data amount, a larger quantization step for a higher compression ratio is set, and one memory (first memory) is cleared. With this setting, the compression ratio of encoding after the encoded data amount reaches the target data amount is increased. Since encoded data before the generated code amount reaches the target data amount are stored in the other memory (second memory), the data are re-encoded at a larger quantization step, and the re-encoding results are stored in the first memory. This process is repeated every time the data amount reaches the target data amount.
Some methods adopt not only the above-mentioned lossy encoding method but also a lossless encoding method. The lossless encoding method is applied to non-natural pictures such as a character image and line image, whereas the lossy encoding method is applied to natural pictures. For this purpose, there is proposed a method of determining the attribute of each part of an image in advance, and switching the encoding method on the basis of the determination result (Japanese Patent Laid-Open No. 7-123273).
Unlike the technique (Japanese Patent Laid-Open No. 2003-8903) of executing re-encoding in accordance with the encoded data amount in the process of encoding, a technique of keeping an entire image in a predetermined code amount while selectively applying either of lossless encoding and lossy encoding to a plurality of areas in an image is also available (Japanese Patent Laid-Open No. 10-224640).
However, the compression encoding technique in Japanese Patent Laid-Open No. 2003-8903 uses only a lossy compression technique such as JPEG. If the data amount does not fall within a predetermined size, the quantization step is set larger to uniformly increase the compression ratio of an entire image, which is highly likely to degrade the image. Especially when an image containing a character/line image and natural picture is to be compression-encoded, the natural picture is hardly influenced by the increase in quantization step, but the influence on the character/line image cannot be ignored.
To solve this problem, encoding specialized in each area is performed by applying lossless encoding to a character/line image and lossy encoding to a natural picture, and encoding with high image quality can be expected. To implement this, however, an attribute determination process for images must be performed as a pre-process, and the attribute must be accurately determined.